from vectors import *
from teapot import load_triangles
from draw_model import draw_model
from math import sin,cos

# 5.1
def linear_combination(scalars,*vectors):
    scaled = [scale(s,v) for s,v in zip(scalars,vectors)]
    return add(*scaled)

def multiply_matrix_vector(matrix, vector):
    return linear_combination(vector, *zip(*matrix))

def matrix_multiply(a,b):
    return tuple(
        tuple(dot(row,col) for col in zip(*b))
        for row in a
    )

def get_rotation_matrix(t): #1
    seconds = t/1000 #2
    return (
        (cos(seconds),0,-sin(seconds)),
        (0,1,0),
        (sin(seconds),0,cos(seconds))
    )

B = (
    (0,2,1),
    (0,1,0),
    (1,0,-1)
)

v = (3,-2,5)

print(list(zip(*B)))
print(multiply_matrix_vector(B,v))

a = ((1,1,0),(1,0,1),(1,-1,1))
b = ((0,2,1),(0,1,0),(1,0,-1))
print(matrix_multiply(a,b))

c = ((1,2),(3,4))
d = ((0,-1),(1,0))
print(matrix_multiply(c,d))

# ####################################################################
# #### this code takes a snapshot to reproduce the exact figure 
# #### shown in the book as an image saved in the "figs" directory
# #### to run it, run this script with command line arg --snapshot
# import sys
# import camera
# if '--snapshot' in sys.argv:
#     camera.default_camera = camera.Camera('fig_5.4_draw_teapot',[0,1000,2000,3000,4000])
# ####################################################################

# draw_model(load_triangles(), get_matrix=get_rotation_matrix)

# 练习5.1
def infer_matrix(n, tranformation):
    standard_basis_vectors = ((1,0,0), (0,1,0), (0,0,1))

# 5.2

# 练习5.18
def transpose(matrix):
    return tuple(zip(*matrix))

print("练习5.18:")
print(transpose(((1,),(2,),(3,))))
print(transpose(((1, 2, 3),)))
